package initialize

import (
	"context"

	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/system"
	"github.com/flipped-aurora/gin-vue-admin/server/plugin/plugin-tool/utils"
)

// Menu 注册菜单到数据库
func Menu(ctx context.Context) {
	// 智能表单菜单配置
	entities := []system.SysBaseMenu{
		// 主菜单：智能表单
		{
			ParentId:  0,
			Path:      "intelligentForm",
			Name:      "intelligentForm",
			Hidden:    false,
			Component: "view/routerHolder.vue",
			Sort:      4,
			Meta: system.Meta{
				KeepAlive:   true,
				DefaultMenu: false,
				Title:       "智能表单",
				Icon:        "menu",
				CloseTab:    false,
			},
		},
		// 子菜单：表单管理
		{
			ParentId:  0, // 会被自动设置为父菜单ID
			Path:      "formList",
			Name:      "formList",
			Hidden:    false,
			Component: "plugin/gva_intelligent_form/view/FormList.vue",
			Sort:      1,
			Meta: system.Meta{
				KeepAlive:   true,
				DefaultMenu: false,
				Title:       "表单管理",
				Icon:        "list",
				CloseTab:    false,
			},
		},
		// 子菜单：表单编辑器
		{
			ParentId:  0, // 会被自动设置为父菜单ID
			Path:      "formEditor",
			Name:      "formEditor",
			Hidden:    false,
			Component: "plugin/gva_intelligent_form/view/FormEditor.vue",
			Sort:      2,
			Meta: system.Meta{
				KeepAlive:   true,
				DefaultMenu: false,
				Title:       "表单编辑器",
				Icon:        "edit",
				CloseTab:    false,
			},
		},
		// 子菜单：表单预览
		{
			ParentId:  0, // 会被自动设置为父菜单ID
			Path:      "formPreview",
			Name:      "formPreview",
			Hidden:    true,
			Component: "plugin/gva_intelligent_form/view/FormPreview.vue",
			Sort:      3,
			Meta: system.Meta{
				KeepAlive:   true,
				DefaultMenu: false,
				Title:       "表单预览",
				Icon:        "view",
				CloseTab:    false,
			},
		},
		// 子菜单：表单填写
		{
			ParentId:  0, // 会被自动设置为父菜单ID
			Path:      "formFill",
			Name:      "formFill",
			Hidden:    true,
			Component: "plugin/gva_intelligent_form/view/FormFill.vue",
			Sort:      4,
			Meta: system.Meta{
				KeepAlive:   true,
				DefaultMenu: false,
				Title:       "表单填写",
				Icon:        "edit-pen",
				CloseTab:    false,
			},
		},
		// 子菜单：数据统计
		{
			ParentId:  0, // 会被自动设置为父菜单ID
			Path:      "formAnalytics/:id",
			Name:      "FormAnalytics",
			Hidden:    true,
			Component: "plugin/gva_intelligent_form/view/FormAnalytics.vue",
			Sort:      5,
			Meta: system.Meta{
				KeepAlive:   true,
				DefaultMenu: false,
				Title:       "数据统计",
				Icon:        "pie-chart",
				CloseTab:    false,
			},
		},
	}

	// 添加日志以便调试
	global.GVA_LOG.Info("正在注册智能表单插件菜单...")
	utils.RegisterMenus(entities...)
	global.GVA_LOG.Info("智能表单插件菜单注册完成")
}
